package com.adjy.pathbuilders.scenario;

import com.adjy.pathbuilders.commons.InvalidSourceException;
import com.adjy.pathbuilders.commons.Storable;

/**
 * Represents the type of the object. Type here is understood as the role 
 * this object will play in the game.
 */
public enum ScenarioObjectType implements Storable {
	MainCharacter("MainCharacter"),
	
	Wall("Wall"), Floor("Floor"),
	
	Door("Door"), Cloud("Cloud"), Apple("Apple"), Time("Time"), ShowDoor("Show_door"),
	
	BadItem("BadItem"), Adrenalin("Adrenalin"), Drink("Drink"), Box("Box"),
	
	GoodItem("GoodItem"), Life("Life"), Coin("Coin"), Fire("Fire");

	
	private String representation;
	
	private ScenarioObjectType(String representation) {
		this.representation = representation;
	}
	
	@Override
	public String toStore() {
		return representation;
	}

	/**
	 * Returns the {@link ScenarioObjectType} represented by the given source. The {@link String}
	 * source must be generated by the toStore method of this class or follow the same
	 * pattern.
	 * @param source the {@link String} source.
	 * @return a {@link ScenarioObjectType}
	 * @throws InvalidSourceException if any data is missing. This may occur if
	 * the given source was not generated using the pattern used by toStore.
	 */
	public static ScenarioObjectType load(String source) throws InvalidSourceException {
		for (ScenarioObjectType type : ScenarioObjectType.values()) {
			if (type.toStore().equals(source)) {
				return type;
			}
		}
		throw new InvalidSourceException(source);
	}
}
